package com.wc.alorithm_blue_bridge._思维.未来竞赛;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2025/3/29 13:27
 * @description
 * https://www.lanqiao.cn/problems/20273/learning/?contest_id=250
 */
public class Main {
    /**
     * 思路：每个国家最多有两个那就是 0 1 2, 方案数
     * 然后乘起来 - 1即可
     */

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static Map<Integer, ArrayList<Integer>> city = new HashMap<>();
    static int n, m, P = (int)1e9 + 7;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for(int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            ArrayList<Integer> group;
            if (city.containsKey(x)) group = city.get(x);
            else {
                group = new ArrayList<>();
                city.put(x, group);
            }
            group.add(i);
        }
        long res = 1;
        for (ArrayList<Integer> g : city.values()) {
            // 全部不选
            long sum = 1;
            // 选一个
            int siz = g.size();
            sum += siz;
            // 选择两个
            for (int i = 0; i < siz; i++) {
                int x = g.get(i), l = i, r = siz - 1;
                while (l < r) {
                    int mid = l + r + 1 >> 1, p = g.get(mid);
                    if (p - x <= m) l = mid;
                    else r = mid - 1;
                }
                sum = (sum + r - i) % P;
            }
            res = res * sum % P;
        }
        res = ((res - 1) % P + P) % P;
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

